/*

Copyright (c) 2013.  All rights reserved.
An Open Source Arduino based OSD, LED Driver and LC Power Supply Filter for Camera & VTX project.

Program  : Bluuu-AQ-OSD
Version  : V0.1, 20.08.2013
Author(s): bluuu
Coauthor(s):
Jani Hirvinen   (All the EEPROM routines) (based on MinimOSD)
Michael Oborne  (OSD Configutator) (based on MinimOSD)
Mike Smith      (BetterStream and Fast Serial libraries) (based on MinimOSD)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>

*/

// DEFINICJE

#undef PROGMEM 
#define PROGMEM __attribute__(( section(".progmem.data") )) 

#undef PSTR 
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) 

//#define isPAL 1

//Biblioteki
#include <FastSerial.h>
#include <AP_Common.h>
#include <AP_Math.h>
#include <math.h>
#include <inttypes.h>
#include <avr/pgmspace.h>
// Get the common arduino functions
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "wiring.h"
#endif
#include <EEPROM.h>
#include <SimpleTimer.h>
#include <AQ_MAVLink.h>

#include "config_hw.h"
#include "eeprom_vars.h"
#include "ArduCam_Max7456.h"


//Zmienne i definicje

FastSerialPort0(Serial);
OSD osd;
SimpleTimer mavlinkTimer;

void setup()
{
  io_init(); //zainicjowanie wejsc i wyjsc
  Serial.begin(uart_speed); //start UART
  mavlink_comm_0_port = &Serial;
  digitalWrite(MAX7456_SELECT, HIGH);  
  osd.init(); //inicjalizacja ekranu
  start_screen(); //ekran startowy
  detect_screen();
  selftest_led();
  selftest_buz();
  countdown_screen();
  Serial.flush();  
}

void loop()
{
  read_mavlink();
  // put your main code here, to run repeatedly:
  delay(5000);
}

//Funkcje
void write_settings() {

writeEEPROM (uart_speed, UART_SPEED_ADDR);
writeEEPROM (1, PAL_NTSC_ADDR);
};

byte readEEPROM(int address) {

    return EEPROM.read(address);
};

void writeEEPROM(byte value, int address) {
    EEPROM.write(address, value);
};

